iT邦幫忙

2024 iThome 鐵人賽

DAY 4
0

今天來解YKL03(UVA10812):Beat the Spread!

Beat the Spread!

https://ithelp.ithome.com.tw/upload/images/20240918/20155574iLvpC3ZD0z.png

給一個s(sum)和d(difference)
要output最後比賽的分數

( s + d ) / 2
( s - d ) / 2
s 一定要大於 d
且相加要是偶數

#include <iostream>
using namespace std;

int main(){
	int s,d,cases;
	cin >> cases;
	while(cases){
		int a,b;
		cin >> s >> d;
		if((s + d) % 2 == 0 && (s - d) % 2 == 0){
			a = (s + d) / 2;
			b = (s - d) / 2;
			if(a >= 0 && b >= 0){
				cout << a << " " << b << endl;
			}
			else{
				cout << "impossible" << endl;
			}
		}else{
			cout << "impossible" << endl;
		}
		cases--;
	}
	return 0;
}

上一篇
CPE C++ 刷題 Day 3
下一篇
CPE C++ 刷題 Day 5
系列文
CPE C++ 刷題20
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言